package com.woniu.inlet.web;

import com.woniu.outlet.po.CompanyTask;
import com.woniu.service.ICompanyTaskService;
import com.woniu.util.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/*
客户可以申请办理业务，当然也可以指定办理业务的客户经理，如果是某一个客户经理完成的业务，那么就会在业务表上添加一条业务，
业务的多少是奖金的评判标准之一
 */

@RestController
@RequestMapping("/cli")
@Api(tags = "客户申请办理业务")
public class CompanyTaskController {

    @Autowired
    private ICompanyTaskService companyTaskService;

    //这个是客户申请办理业务的
    @ApiOperation(value = "addtask",notes = "客户申请办理业务")
    @PostMapping("/addtask")
    @PreAuthorize("hasRole('client')")
    public ResponseResult<String> addtask(@RequestBody CompanyTask companyTask){
        int addtask = companyTaskService.addtask(companyTask);
        return new ResponseResult<>("申请成功！！",200);
    }

    //客户经理查看自己任务信息
    @ApiImplicitParams({
            @ApiImplicitParam(value = "客户经理的id", name = "workerid", required = true
            ,paramType = "query",dataType = "Integer")
    })
    @ApiOperation(value = "findmytask",notes = "客户经理查看自己任务信息")
    @GetMapping("/findmytask")
    @PreAuthorize("hasRole('client')")
    public ResponseResult<List<CompanyTask>> findmytask(Integer workerid){
        List<CompanyTask> findmytasklist = companyTaskService.findmytask(workerid);
        return new ResponseResult<>(findmytasklist,200);
    }


    //客户经理来处理客户的业务信息，处理完成之后，还要添加业务表的一条信息
    @ApiImplicitParams({
            @ApiImplicitParam(value = "客户任务id", name = "companytaskId", required = true,paramType = "query",dataType = "Integer"),
            @ApiImplicitParam(value = "客户经理的id", name = "workerid", required = true,paramType = "query",dataType = "Integer"),
            @ApiImplicitParam(value = "对公客户的id", name = "companyid", required = true,paramType = "query",dataType = "Integer"),
            @ApiImplicitParam(value = "客户任务类型", name = "companytaskType", required = true,paramType = "query",dataType = "Integer")
    })
    @ApiOperation(value = "handletask",notes = "客户经理来处理客户的业务信息，处理完成之后，还要添加业务表的一条信息")
    @GetMapping("/handletask")
    @PreAuthorize("hasRole('client')")
    public ResponseResult<String> handletask(Integer companytaskId,Integer workerid,Integer companyid,Integer companytaskType){
        int handletask = companyTaskService.handletask(companytaskId, workerid, companyid, companytaskType);
        return new ResponseResult<>("处理成功！！",200);
    }


}
